package com.ecable.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ecable.bean.ProfileTO;
import com.ecable.daoImpl.ProfileDAO;
import com.ecable.util.UtilConstants;

public class ViewUserAction extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		doPost(request, response);
	}

	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

               
		String path="";
		HttpSession session=request.getSession();
		String user=(String)session.getAttribute("user");
		Vector<ProfileTO> opv=null;
		try{
	
			
			String path1=request.getRealPath("/images");
				 
				 opv=new ProfileDAO().viewUser(path1,user);
				
			if(!opv.isEmpty()){
				request.setAttribute("status", UtilConstants._USER_INFO);
				request.setAttribute("userinfo", opv);
				request.setAttribute("user", user);
				path=UtilConstants._VIEW_ALL__USER;
		
			}
			else
			{
				
				request.setAttribute("status", UtilConstants._NO__OUSER);
				request.setAttribute("user", user);
				path=UtilConstants._VIEW_ALL__USER;
				
			}
			
		}
		catch (Exception e) {
			
			request.setAttribute("status", UtilConstants._INVALIED_ENTRY);
			path=UtilConstants._VIEW_ALL__USER;
			
		}
		RequestDispatcher rd=request.getRequestDispatcher(path);
		
		rd.forward(request, response);
		
   }

}
